<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>树洞详情 - 树洞交友</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome 图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    
    <style>
        :root {
            --primary: #4f46e5;
            --primary-light: #818cf8;
            --primary-dark: #3730a3;
            --secondary: #ec4899;
            --success: #10b981;
            --warning: #f59e0b;
            --danger: #ef4444;
            --text-primary: #1f2937;
            --text-secondary: #6b7280;
            --text-light: #9ca3af;
            --bg-light: #f9fafb;
            --bg-white: #ffffff;
            --border-light: #e5e7eb;
            --radius: 10px;
            --shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            background-color: var(--bg-light);
            color: var(--text-primary);
            padding-top: 55px;
            padding-bottom: 65px;
        }
        
        /* 顶部导航 */
        .top-nav {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 55px;
            background-color: var(--bg-white);
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 15px;
            z-index: 1000;
            border-bottom: 1px solid var(--border-light);
            box-shadow: var(--shadow);
        }
        
        .nav-title {
            font-size: 1.1rem;
            font-weight: 600;
        }
        
        .nav-action {
            color: var(--text-secondary);
            background: none;
            border: none;
            font-size: 1.2rem;
        }
        
        /* 树洞详情容器 */
        .treehole-detail {
            background-color: var(--bg-white);
            padding: 15px;
            margin-bottom: 12px;
        }
        
        /* 作者信息 */
        .author-info {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 15px;
        }
        
        .author-avatar {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            object-fit: cover;
        }
        
        .author-name {
            font-weight: 600;
            font-size: 1rem;
        }
        
        .post-time {
            font-size: 0.8rem;
            color: var(--text-light);
            display: flex;
            align-items: center;
            gap: 5px;
        }
        
        .follow-btn {
            margin-left: auto;
            padding: 5px 12px;
            background-color: var(--primary);
            color: white;
            border: none;
            border-radius: 15px;
            font-size: 0.85rem;
        }
        
        .follow-btn.following {
            background-color: var(--bg-light);
            color: var(--text-secondary);
        }
        
        /* 树洞内容 */
        .treehole-content {
            font-size: 1rem;
            line-height: 1.6;
            margin-bottom: 15px;
        }
        
        /* 图片容器 */
        .images-container {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 6px;
            margin-bottom: 15px;
            border-radius: 6px;
            overflow: hidden;
        }
        
        .images-container.single {
            grid-template-columns: 1fr;
        }
        
        .images-container.double {
            grid-template-columns: repeat(2, 1fr);
        }
        
        .treehole-image {
            width: 100%;
            height: 100%;
            object-fit: cover;
            aspect-ratio: 1/1;
        }
        
        .images-container.single .treehole-image {
            aspect-ratio: 4/3;
        }
        
        /* 标签 */
        .tags-container {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-bottom: 15px;
        }
        
        .post-tag {
            padding: 3px 10px;
            background-color: rgba(79, 70, 229, 0.1);
            color: var(--primary);
            border-radius: 12px;
            font-size: 0.8rem;
        }
        
        /* 操作按钮 */
        .action-buttons {
            display: flex;
            justify-content: space-around;
            padding: 10px 0;
            border-top: 1px solid var(--border-light);
            border-bottom: 1px solid var(--border-light);
            margin-bottom: 15px;
        }
        
        .action-btn {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 5px;
            color: var(--text-secondary);
            background: none;
            border: none;
            font-size: 0.8rem;
        }
        
        .action-btn.liked {
            color: var(--danger);
        }
        
        .action-btn i {
            font-size: 1.2rem;
        }
        
        /* 分享弹窗 */
        .share-modal {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background-color: var(--bg-white);
            border-radius: var(--radius) var(--radius) 0 0;
            padding: 15px;
            transform: translateY(100%);
            transition: transform 0.3s ease;
            z-index: 1010;
        }
        
        .share-modal.show {
            transform: translateY(0);
        }
        
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 1005;
            display: none;
        }
        
        .modal-overlay.show {
            display: block;
        }
        
        .share-title {
            text-align: center;
            font-weight: 600;
            margin-bottom: 20px;
        }
        
        .share-options {
            display: flex;
            justify-content: space-around;
            margin-bottom: 20px;
        }
        
        .share-option {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 5px;
            color: var(--text-primary);
            text-decoration: none;
            font-size: 0.85rem;
        }
        
        .share-option i {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: var(--bg-light);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.2rem;
        }
        
        .cancel-share {
            width: 100%;
            padding: 10px;
            background-color: var(--bg-light);
            border: none;
            border-radius: var(--radius);
            font-size: 0.95rem;
        }
        
        /* 评论区 */
        .comments-section {
            background-color: var(--bg-white);
            padding: 15px;
        }
        
        .comments-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .comments-title {
            font-weight: 600;
            font-size: 1rem;
        }
        
        .sort-comments {
            color: var(--text-secondary);
            background: none;
            border: none;
            font-size: 0.85rem;
            display: flex;
            align-items: center;
            gap: 5px;
        }
        
        /* 评论输入框 */
        .comment-input-container {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }
        
        .comment-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            object-fit: cover;
        }
        
        .comment-input-group {
            flex: 1;
            position: relative;
        }
        
        .comment-input {
            width: 100%;
            padding: 10px 15px;
            border-radius: 20px;
            border: 1px solid var(--border-light);
            background-color: var(--bg-light);
            font-size: 0.9rem;
            resize: none;
            height: 40px;
        }
        
        .comment-input:focus {
            outline: none;
            border-color: var(--primary-light);
        }
        
        .send-comment {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            background-color: var(--primary);
            color: white;
            border: none;
            border-radius: 50%;
            width: 28px;
            height: 28px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.8rem;
        }
        
        /* 评论列表 */
        .comments-list {
            margin-bottom: 20px;
        }
        
        .comment-item {
            display: flex;
            gap: 10px;
            margin-bottom: 15px;
            padding-bottom: 15px;
            border-bottom: 1px solid var(--border-light);
        }
        
        .comment-item:last-child {
            border-bottom: none;
            margin-bottom: 0;
            padding-bottom: 0;
        }
        
        .comment-content {
            flex: 1;
        }
        
        .comment-author {
            font-weight: 500;
            font-size: 0.9rem;
            margin-bottom: 5px;
        }
        
        .comment-text {
            font-size: 0.9rem;
            margin-bottom: 8px;
            background-color: var(--bg-light);
            padding: 8px 12px;
            border-radius: var(--radius);
        }
        
        .comment-meta {
            display: flex;
            gap: 15px;
            font-size: 0.8rem;
            color: var(--text-light);
        }
        
        .comment-action {
            color: var(--text-light);
            background: none;
            border: none;
            padding: 0;
            display: flex;
            align-items: center;
            gap: 3px;
        }
        
        .comment-action.liked {
            color: var(--danger);
        }
        
        /* 回复区域 */
        .replies-container {
            margin-left: 30px;
            margin-top: 10px;
        }
        
        .reply-item {
            display: flex;
            gap: 8px;
            margin-bottom: 10px;
        }
        
        .reply-content {
            flex: 1;
        }
        
        .reply-author {
            font-weight: 500;
            font-size: 0.85rem;
        }
        
        .reply-text {
            font-size: 0.85rem;
            margin-bottom: 5px;
            background-color: var(--bg-light);
            padding: 6px 10px;
            border-radius: 8px;
        }
        
        .reply-meta {
            display: flex;
            gap: 10px;
            font-size: 0.75rem;
            color: var(--text-light);
        }
        
        .reply-input-container {
            display: flex;
            gap: 8px;
            margin-top: 10px;
        }
        
        .reply-input {
            flex: 1;
            padding: 6px 10px;
            border-radius: 15px;
            border: 1px solid var(--border-light);
            background-color: var(--bg-light);
            font-size: 0.85rem;
        }
        
        .reply-input:focus {
            outline: none;
            border-color: var(--primary-light);
        }
        
        .send-reply {
            color: var(--primary);
            background: none;
            border: none;
            font-size: 0.85rem;
            padding: 0 8px;
        }
        
        /* 底部导航 */
        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            height: 65px;
            background-color: var(--bg-white);
            display: flex;
            justify-content: space-around;
            align-items: center;
            border-top: 1px solid var(--border-light);
            z-index: 1000;
        }
        
        .nav-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: var(--text-secondary);
            font-size: 0.7rem;
        }
        
        .nav-item i {
            font-size: 1.3rem;
            margin-bottom: 3px;
        }
        
        .nav-item.active {
            color: var(--primary);
        }
        
        .add-post-btn {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: var(--primary);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
            margin-top: -25px;
            box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
        }
        
        /* 加载更多评论 */
        .load-more {
            width: 100%;
            padding: 8px;
            background-color: var(--bg-light);
            border: 1px solid var(--border-light);
            border-radius: var(--radius);
            color: var(--text-secondary);
            font-size: 0.9rem;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <!-- 顶部导航 -->
    <div class="top-nav">
        <button class="nav-action" id="backBtn">
            <i class="fas fa-arrow-left"></i>
        </button>
        <div class="nav-title">树洞详情</div>
        <button class="nav-action" id="moreBtn">
            <i class="fas fa-ellipsis-h"></i>
        </button>
    </div>
    
    <!-- 树洞详情 -->
    <div class="treehole-detail">
        <div class="author-info">
            <img src="https://picsum.photos/id/65/100/100" alt="作者头像" class="author-avatar">
            <div>
                <div class="author-name">咖啡不加糖</div>
                <div class="post-time">
                    <span>昨天 19:45</span>
                    <span class="distance-badge"><i class="fas fa-map-marker-alt"></i> 1.2km</span>
                </div>
            </div>
            <button class="follow-btn">关注</button>
        </div>
        
        <div class="treehole-content">
            周末发现的一家小众咖啡馆，环境特别好，咖啡也很正宗。店主是个很有趣的人，跟我们聊了很多关于咖啡的知识。有没有喜欢探店的朋友，下次可以一起啊~
        </div>
        
        <div class="images-container">
            <img src="https://picsum.photos/id/431/800/800" alt="咖啡馆照片1" class="treehole-image">
            <img src="https://picsum.photos/id/225/800/800" alt="咖啡馆照片2" class="treehole-image">
            <img src="https://picsum.photos/id/766/800/800" alt="咖啡馆照片3" class="treehole-image">
        </div>
        
        <div class="tags-container">
            <span class="post-tag">咖啡</span>
            <span class="post-tag">探店</span>
            <span class="post-tag">周末</span>
            <span class="post-tag">爱好</span>
        </div>
        
        <div class="action-buttons">
            <button class="action-btn" id="commentBtn">
                <i class="far fa-comment"></i>
                <span>18</span>
            </button>
            <button class="action-btn" id="likeBtn">
                <i class="far fa-heart"></i>
                <span>94</span>
            </button>
            <button class="action-btn" id="collectBtn">
                <i class="far fa-star"></i>
                <span>收藏</span>
            </button>
            <button class="action-btn" id="shareBtn">
                <i class="far fa-share-alt"></i>
                <span>分享</span>
            </button>
        </div>
    </div>
    
    <!-- 评论区 -->
    <div class="comments-section">
        <div class="comments-header">
            <div class="comments-title">评论 (18)</div>
            <button class="sort-comments">
                <span>最新</span>
                <i class="fas fa-chevron-down"></i>
            </button>
        </div>
        
        <!-- 评论输入框 -->
        <div class="comment-input-container">
            <img src="https://picsum.photos/id/91/100/100" alt="我的头像" class="comment-avatar">
            <div class="comment-input-group">
                <textarea class="comment-input" placeholder="写下你的评论..."></textarea>
                <button class="send-comment">
                    <i class="fas fa-paper-plane"></i>
                </button>
            </div>
        </div>
        
        <!-- 评论列表 -->
        <div class="comments-list">
            <!-- 评论1 -->
            <div class="comment-item">
                <img src="https://picsum.photos/id/237/100/100" alt="评论者头像" class="comment-avatar">
                <div class="comment-content">
                    <div class="comment-author">旅行者小明</div>
                    <div class="comment-text">这家我去过！他们家的手冲确实不错，老板很懂咖啡</div>
                    <div class="comment-meta">
                        <span>2小时前</span>
                        <button class="comment-action like-comment">
                            <i class="far fa-heart"></i>
                            <span>12</span>
                        </button>
                        <button class="comment-action reply-btn">回复</button>
                    </div>
                    
                    <!-- 回复区域 -->
                    <div class="replies-container">
                        <div class="reply-item">
                            <img src="https://picsum.photos/id/65/100/100" alt="回复者头像" class="comment-avatar">
                            <div class="reply-content">
                                <div class="reply-author">
                                    <span>咖啡不加糖</span>
                                </div>
                                <div class="reply-text">是的，老板以前是咖啡师比赛的评委呢</div>
                                <div class="reply-meta">
                                    <span>1小时前</span>
                                    <button class="comment-action like-reply">
                                        <i class="far fa-heart"></i>
                                        <span>3</span>
                                    </button>
                                    <button class="comment-action reply-btn">回复</button>
                                </div>
                            </div>
                        </div>
                        
                        <!-- 回复输入框 -->
                        <div class="reply-input-container" style="display: none;">
                            <img src="https://picsum.photos/id/91/100/100" alt="我的头像" class="comment-avatar" style="width: 30px; height: 30px;">
                            <input type="text" class="reply-input" placeholder="回复 旅行者小明...">
                            <button class="send-reply">发送</button>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 评论2 -->
            <div class="comment-item">
                <img src="https://picsum.photos/id/177/100/100" alt="评论者头像" class="comment-avatar">
                <div class="comment-content">
                    <div class="comment-author">美食家Lily</div>
                    <div class="comment-text">请问具体位置在哪里呀？看起来环境很好</div>
                    <div class="comment-meta">
                        <span>昨天 21:30</span>
                        <button class="comment-action like-comment">
                            <i class="far fa-heart"></i>
                            <span>8</span>
                        </button>
                        <button class="comment-action reply-btn">回复</button>
                    </div>
                    
                    <!-- 回复输入框 -->
                    <div class="reply-input-container" style="display: none;">
                        <img src="https://picsum.photos/id/91/100/100" alt="我的头像" class="comment-avatar" style="width: 30px; height: 30px;">
                        <input type="text" class="reply-input" placeholder="回复 美食家Lily...">
                        <button class="send-reply">发送</button>
                    </div>
                </div>
            </div>
            
            <!-- 评论3 -->
            <div class="comment-item">
                <img src="https://picsum.photos/id/342/100/100" alt="评论者头像" class="comment-avatar">
                <div class="comment-content">
                    <div class="comment-author">摄影爱好者</div>
                    <div class="comment-text">第三张照片拍得真好，请问用的什么相机？</div>
                    <div class="comment-meta">
                        <span>昨天 20:15</span>
                        <button class="comment-action like-comment liked">
                            <i class="fas fa-heart"></i>
                            <span>5</span>
                        </button>
                        <button class="comment-action reply-btn">回复</button>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 加载更多评论 -->
        <button class="load-more">加载更多评论</button>
    </div>
    
    <!-- 分享弹窗 -->
    <div class="share-modal" id="shareModal">
        <div class="share-title">分享到</div>
        <div class="share-options">
            <a href="#" class="share-option">
                <i class="fab fa-weixin"></i>
                <span>微信</span>
            </a>
            <a href="#" class="share-option">
                <i class="fab fa-weibo"></i>
                <span>微博</span>
            </a>
            <a href="#" class="share-option">
                <i class="fab fa-qq"></i>
                <span>QQ</span>
            </a>
            <a href="#" class="share-option">
                <i class="fas fa-link"></i>
                <span>复制链接</span>
            </a>
            <a href="#" class="share-option">
                <i class="fas fa-save"></i>
                <span>保存图片</span>
            </a>
        </div>
        <button class="cancel-share" id="cancelShare">取消</button>
    </div>
    
    <!-- 遮罩层 -->
    <div class="modal-overlay" id="modalOverlay"></div>
    
    <!-- 底部导航 -->
    <div class="bottom-nav">
        <div class="nav-item">
            <i class="fas fa-home"></i>
            <span>首页</span>
        </div>
        <div class="nav-item">
            <i class="fas fa-compass"></i>
            <span>发现</span>
        </div>
        <div class="add-post-btn">
            <i class="fas fa-plus"></i>
        </div>
        <div class="nav-item">
            <i class="far fa-bell"></i>
            <span>通知</span>
        </div>
        <div class="nav-item active">
            <i class="far fa-user"></i>
            <span>我的</span>
        </div>
    </div>
    
    <!-- Bootstrap JS Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
    
    <script>
        // 返回按钮
        document.getElementById('backBtn').addEventListener('click', () => {
            // 实际应用中这里会返回上一页
            alert('返回上一页');
        });
        
        // 更多选项按钮
        document.getElementById('moreBtn').addEventListener('click', () => {
            alert('显示更多操作选项');
        });
        
        // 关注按钮
        const followBtn = document.querySelector('.follow-btn');
        followBtn.addEventListener('click', () => {
            if (followBtn.classList.contains('following')) {
                followBtn.classList.remove('following');
                followBtn.textContent = '关注';
            } else {
                followBtn.classList.add('following');
                followBtn.textContent = '已关注';
            }
        });
        
        // 点赞功能
        const likeBtn = document.getElementById('likeBtn');
        let likeCount = 94;
        
        likeBtn.addEventListener('click', () => {
            const icon = likeBtn.querySelector('i');
            const countEl = likeBtn.querySelector('span');
            
            if (icon.classList.contains('far')) {
                icon.classList.remove('far');
                icon.classList.add('fas');
                likeBtn.classList.add('liked');
                likeCount++;
            } else {
                icon.classList.remove('fas');
                icon.classList.add('far');
                likeBtn.classList.remove('liked');
                likeCount--;
            }
            
            countEl.textContent = likeCount;
        });
        
        // 收藏功能
        const collectBtn = document.getElementById('collectBtn');
        collectBtn.addEventListener('click', () => {
            const icon = collectBtn.querySelector('i');
            
            if (icon.classList.contains('far')) {
                icon.classList.remove('far');
                icon.classList.add('fas');
                collectBtn.classList.add('liked');
                alert('收藏成功');
            } else {
                icon.classList.remove('fas');
                icon.classList.add('far');
                collectBtn.classList.remove('liked');
                alert('取消收藏');
            }
        });
        
        // 分享功能
        const shareBtn = document.getElementById('shareBtn');
        const shareModal = document.getElementById('shareModal');
        const modalOverlay = document.getElementById('modalOverlay');
        const cancelShare = document.getElementById('cancelShare');
        
        shareBtn.addEventListener('click', () => {
            shareModal.classList.add('show');
            modalOverlay.classList.add('show');
            document.body.style.overflow = 'hidden';
        });
        
        function closeShareModal() {
            shareModal.classList.remove('show');
            modalOverlay.classList.remove('show');
            document.body.style.overflow = '';
        }
        
        cancelShare.addEventListener('click', closeShareModal);
        modalOverlay.addEventListener('click', closeShareModal);
        
        // 评论点赞功能
        const likeCommentBtns = document.querySelectorAll('.like-comment');
        likeCommentBtns.forEach(btn => {
            btn.addEventListener('click', () => {
                const icon = btn.querySelector('i');
                const countEl = btn.querySelector('span');
                let count = parseInt(countEl.textContent);
                
                if (icon.classList.contains('far')) {
                    icon.classList.remove('far');
                    icon.classList.add('fas');
                    btn.classList.add('liked');
                    countEl.textContent = count + 1;
                } else {
                    icon.classList.remove('fas');
                    icon.classList.add('far');
                    btn.classList.remove('liked');
                    countEl.textContent = count - 1;
                }
            });
        });
        
        // 回复点赞功能
        const likeReplyBtns = document.querySelectorAll('.like-reply');
        likeReplyBtns.forEach(btn => {
            btn.addEventListener('click', () => {
                const icon = btn.querySelector('i');
                const countEl = btn.querySelector('span');
                let count = parseInt(countEl.textContent);
                
                if (icon.classList.contains('far')) {
                    icon.classList.remove('far');
                    icon.classList.add('fas');
                    btn.classList.add('liked');
                    countEl.textContent = count + 1;
                } else {
                    icon.classList.remove('fas');
                    icon.classList.add('far');
                    btn.classList.remove('liked');
                    countEl.textContent = count - 1;
                }
            });
        });
        
        // 回复功能
        const replyBtns = document.querySelectorAll('.reply-btn');
        replyBtns.forEach(btn => {
            btn.addEventListener('click', () => {
                // 隐藏所有回复框
                document.querySelectorAll('.reply-input-container').forEach(container => {
                    container.style.display = 'none';
                });
                
                // 显示当前评论的回复框
                const commentItem = btn.closest('.comment-item, .reply-item');
                const replyContainer = commentItem.querySelector('.replies-container') 
                    ? commentItem.querySelector('.replies-container .reply-input-container')
                    : commentItem.nextElementSibling;
                
                if (replyContainer) {
                    replyContainer.style.display = 'flex';
                    replyContainer.querySelector('.reply-input').focus();
                }
            });
        });
        
        // 发送回复
        const sendReplyBtns = document.querySelectorAll('.send-reply');
        sendReplyBtns.forEach(btn => {
            btn.addEventListener('click', () => {
                const input = btn.previousElementSibling;
                const replyText = input.value.trim();
                
                if (replyText) {
                    // 获取回复容器
                    const repliesContainer = btn.closest('.replies-container') || btn.closest('.comment-content');
                    
                    // 创建新回复元素
                    const newReply = document.createElement('div');
                    newReply.className = 'reply-item';
                    newReply.innerHTML = `
                        <img src="https://picsum.photos/id/91/100/100" alt="我的头像" class="comment-avatar">
                        <div class="reply-content">
                            <div class="reply-author">我</div>
                            <div class="reply-text">${replyText}</div>
                            <div class="reply-meta">
                                <span>刚刚</span>
                                <button class="comment-action like-reply">
                                    <i class="far fa-heart"></i>
                                    <span>0</span>
                                </button>
                                <button class="comment-action reply-btn">回复</button>
                            </div>
                        </div>
                    `;
                    
                    // 添加到回复容器的最前面
                    if (repliesContainer.querySelector('.reply-item')) {
                        repliesContainer.insertBefore(newReply, repliesContainer.querySelector('.reply-item'));
                    } else {
                        repliesContainer.appendChild(newReply);
                    }
                    
                    // 清空输入框并隐藏
                    input.value = '';
                    btn.closest('.reply-input-container').style.display = 'none';
                    
                    // 为新回复绑定事件
                    bindReplyEvents(newReply);
                    
                    // 更新评论数
                    updateCommentCount(1);
                }
            });
        });
        
        // 发送评论
        const sendCommentBtn = document.querySelector('.send-comment');
        sendCommentBtn.addEventListener('click', () => {
            const input = document.querySelector('.comment-input');
            const commentText = input.value.trim();
            
            if (commentText) {
                // 创建新评论元素
                const newComment = document.createElement('div');
                newComment.className = 'comment-item';
                newComment.innerHTML = `
                    <img src="https://picsum.photos/id/91/100/100" alt="我的头像" class="comment-avatar">
                    <div class="comment-content">
                        <div class="comment-author">我</div>
                        <div class="comment-text">${commentText}</div>
                        <div class="comment-meta">
                            <span>刚刚</span>
                            <button class="comment-action like-comment">
                                <i class="far fa-heart"></i>
                                <span>0</span>
                            </button>
                            <button class="comment-action reply-btn">回复</button>
                        </div>
                        
                        <!-- 回复输入框 -->
                        <div class="reply-input-container" style="display: none;">
                            <img src="https://picsum.photos/id/91/100/100" alt="我的头像" class="comment-avatar" style="width: 30px; height: 30px;">
                            <input type="text" class="reply-input" placeholder="回复...">
                            <button class="send-reply">发送</button>
                        </div>
                    </div>
                `;
                
                // 添加到评论列表的最前面
                const commentsList = document.querySelector('.comments-list');
                commentsList.insertBefore(newComment, commentsList.firstChild);
                
                // 清空输入框
                input.value = '';
                
                // 为新评论绑定事件
                bindCommentEvents(newComment);
                
                // 更新评论数
                updateCommentCount(1);
            }
        });
        
        // 评论输入框自动调整高度
        const commentInput = document.querySelector('.comment-input');
        commentInput.addEventListener('input', () => {
            // 重置高度
            commentInput.style.height = 'auto';
            // 设置新高度（最小40px，最大120px）
            const newHeight = Math.min(120, Math.max(40, commentInput.scrollHeight));
            commentInput.style.height = newHeight + 'px';
        });
        
        // 加载更多评论
        document.querySelector('.load-more').addEventListener('click', function() {
            const btn = this;
            btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 加载中...';
            
            // 模拟加载延迟
            setTimeout(() => {
                const commentsList = document.querySelector('.comments-list');
                
                // 添加两条新评论
                for (let i = 0; i < 2; i++) {
                    const newComment = document.createElement('div');
                    newComment.className = 'comment-item';
                    newComment.innerHTML = `
                        <img src="https://picsum.photos/id/${350 + i}/100/100" alt="评论者头像" class="comment-avatar">
                        <div class="comment-content">
                            <div class="comment-author">用户${350 + i}</div>
                            <div class="comment-text">看起来真不错，下次有空去看看，谢谢分享！</div>
                            <div class="comment-meta">
                                <span>${i + 1}天前</span>
                                <button class="comment-action like-comment">
                                    <i class="far fa-heart"></i>
                                    <span>${Math.floor(Math.random() * 10)}</span>
                                </button>
                                <button class="comment-action reply-btn">回复</button>
                            </div>
                        </div>
                    `;
                    
                    commentsList.appendChild(newComment);
                    bindCommentEvents(newComment);
                }
                
                btn.textContent = '加载更多评论';
                
                // 如果没有更多评论了
                if (Math.random() > 0.7) {
                    btn.textContent = '没有更多评论了';
                    btn.disabled = true;
                    btn.style.opacity = '0.7';
                }
            }, 1500);
        });
        
        // 评论排序
        document.querySelector('.sort-comments').addEventListener('click', function() {
            const currentSort = this.querySelector('span').textContent;
            const newSort = currentSort === '最新' ? '最热' : '最新';
            
            this.querySelector('span').textContent = newSort;
            
            // 模拟排序动画
            const commentsList = document.querySelector('.comments-list');
            commentsList.style.opacity = '0.5';
            
            setTimeout(() => {
                commentsList.style.opacity = '1';
                // 实际应用中这里会根据排序方式重新排列评论
            }, 500);
        });
        
        // 点击评论按钮滚动到评论区
        document.getElementById('commentBtn').addEventListener('click', () => {
            document.querySelector('.comments-section').scrollIntoView({
                behavior: 'smooth'
            });
            document.querySelector('.comment-input').focus();
        });
        
        // 更新评论数量
        function updateCommentCount(change) {
            const commentCountEl = document.querySelector('.comments-title');
            const commentBtnCount = document.getElementById('commentBtn').querySelector('span');
            
            let count = parseInt(commentCountEl.textContent.match(/\d+/)[0]);
            count += change;
            
            commentCountEl.textContent = `评论 (${count})`;
            commentBtnCount.textContent = count;
        }
        
        // 绑定评论事件
        function bindCommentEvents(commentElement) {
            // 评论点赞
            const likeBtn = commentElement.querySelector('.like-comment');
            likeBtn.addEventListener('click', () => {
                const icon = likeBtn.querySelector('i');
                const countEl = likeBtn.querySelector('span');
                let count = parseInt(countEl.textContent) || 0;
                
                if (icon.classList.contains('far')) {
                    icon.classList.remove('far');
                    icon.classList.add('fas');
                    likeBtn.classList.add('liked');
                    countEl.textContent = count + 1;
                } else {
                    icon.classList.remove('fas');
                    icon.classList.add('far');
                    likeBtn.classList.remove('liked');
                    countEl.textContent = count - 1;
                }
            });
            
            // 回复按钮
            const replyBtn = commentElement.querySelector('.reply-btn');
            replyBtn.addEventListener('click', () => {
                // 隐藏所有回复框
                document.querySelectorAll('.reply-input-container').forEach(container => {
                    container.style.display = 'none';
                });
                
                // 显示当前评论的回复框
                const replyContainer = commentElement.querySelector('.reply-input-container');
                if (replyContainer) {
                    replyContainer.style.display = 'flex';
                    replyContainer.querySelector('.reply-input').focus();
                }
            });
            
            // 发送回复
            const sendReplyBtn = commentElement.querySelector('.send-reply');
            if (sendReplyBtn) {
                sendReplyBtn.addEventListener('click', () => {
                    const input = sendReplyBtn.previousElementSibling;
                    const replyText = input.value.trim();
                    
                    if (replyText) {
                        // 创建新回复
                        const repliesContainer = document.createElement('div');
                        repliesContainer.className = 'replies-container';
                        
                        const newReply = document.createElement('div');
                        newReply.className = 'reply-item';
                        newReply.innerHTML = `
                            <img src="https://picsum.photos/id/91/100/100" alt="我的头像" class="comment-avatar">
                            <div class="reply-content">
                                <div class="reply-author">我</div>
                                <div class="reply-text">${replyText}</div>
                                <div class="reply-meta">
                                    <span>刚刚</span>
                                    <button class="comment-action like-reply">
                                        <i class="far fa-heart"></i>
                                        <span>0</span>
                                    </button>
                                    <button class="comment-action reply-btn">回复</button>
                                </div>
                            </div>
                        `;
                        
                        repliesContainer.appendChild(newReply);
                        commentElement.querySelector('.comment-content').appendChild(repliesContainer);
                        
                        // 隐藏回复框并清空
                        input.value = '';
                        input.closest('.reply-input-container').style.display = 'none';
                        
                        // 绑定新回复的事件
                        bindReplyEvents(newReply);
                        
                        // 更新评论数
                        updateCommentCount(1);
                    }
                });
            }
        }
        
        // 绑定回复事件
        function bindReplyEvents(replyElement) {
            // 回复点赞
            const likeBtn = replyElement.querySelector('.like-reply');
            likeBtn.addEventListener('click', () => {
                const icon = likeBtn.querySelector('i');
                const countEl = likeBtn.querySelector('span');
                let count = parseInt(countEl.textContent) || 0;
                
                if (icon.classList.contains('far')) {
                    icon.classList.remove('far');
                    icon.classList.add('fas');
                    likeBtn.classList.add('liked');
                    countEl.textContent = count + 1;
                } else {
                    icon.classList.remove('fas');
                    icon.classList.add('far');
                    likeBtn.classList.remove('liked');
                    countEl.textContent = count - 1;
                }
            });
            
            // 回复的回复按钮
            const replyBtn = replyElement.querySelector('.reply-btn');
            replyBtn.addEventListener('click', () => {
                // 隐藏所有回复框
                document.querySelectorAll('.reply-input-container').forEach(container => {
                    container.style.display = 'none';
                });
                
                // 创建或显示回复框
                let repliesContainer = replyElement.closest('.replies-container');
                let replyContainer = repliesContainer.querySelector('.reply-input-container');
                
                if (!replyContainer) {
                    replyContainer = document.createElement('div');
                    replyContainer.className = 'reply-input-container';
                    replyContainer.innerHTML = `
                        <img src="https://picsum.photos/id/91/100/100" alt="我的头像" class="comment-avatar" style="width: 30px; height: 30px;">
                        <input type="text" class="reply-input" placeholder="回复 ${replyElement.querySelector('.reply-author').textContent}...">
                        <button class="send-reply">发送</button>
                    `;
                    
                    repliesContainer.appendChild(replyContainer);
                    
                    // 绑定发送回复事件
                    replyContainer.querySelector('.send-reply').addEventListener('click', function() {
                        const input = this.previousElementSibling;
                        const replyText = input.value.trim();
                        
                        if (replyText) {
                            const newReply = document.createElement('div');
                            newReply.className = 'reply-item';
                            newReply.innerHTML = `
                                <img src="https://picsum.photos/id/91/100/100" alt="我的头像" class="comment-avatar">
                                <div class="reply-content">
                                    <div class="reply-author">我</div>
                                    <div class="reply-text">${replyText}</div>
                                    <div class="reply-meta">
                                        <span>刚刚</span>
                                        <button class="comment-action like-reply">
                                            <i class="far fa-heart"></i>
                                            <span>0</span>
                                        </button>
                                        <button class="comment-action reply-btn">回复</button>
                                    </div>
                                </div>
                            `;
                            
                            repliesContainer.insertBefore(newReply, replyContainer);
                            
                            // 清空输入框并隐藏
                            input.value = '';
                            replyContainer.style.display = 'none';
                            
                            // 绑定新回复的事件
                            bindReplyEvents(newReply);
                            
                            // 更新评论数
                            updateCommentCount(1);
                        }
                    });
                }
                
                replyContainer.style.display = 'flex';
                replyContainer.querySelector('.reply-input').focus();
            });
        }
        
        // 初始化绑定事件
        document.querySelectorAll('.comment-item').forEach(comment => {
            bindCommentEvents(comment);
        });
        
        document.querySelectorAll('.reply-item').forEach(reply => {
            bindReplyEvents(reply);
        });
        
        // 发布按钮点击事件
        document.querySelector('.add-post-btn').addEventListener('click', () => {
            alert('跳转到发布树洞页面');
        });
    </script>
</body>
</html>


